package com.ch999.detect.View.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.ch999.detect.R;
import com.ch999.detect.mode.bean.GoodsBjgz;

import java.util.List;

/**
 * Created by Administrator on 2016/12/13 0013.
 */

public class CheckFactionAdatper extends RecyclerView.Adapter<CheckFactionAdatper.ViewHolder> {
    public Context mContext;
    List<GoodsBjgz.AttrBean> data;

    public CheckFactionAdatper(Context context, List<GoodsBjgz.AttrBean> data) {
        this.mContext = context;
        this.data = data;
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ViewHolder holder = new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.check_layout, parent, false));
        return holder;
    }

    @Override
    public int getItemCount() {
        if (data == null) {
            return 0;
        }
        return data.size();
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {

        GoodsBjgz.AttrBean attrBean = data.get(position);

        holder.mCbCheck.setText(attrBean.getValues().get(1).getName());
        holder.mCbCheck.setTag(position);
        holder.mCbCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                Log.e("adapter", "onCheckedChanged: " + b);
            }
        });
    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        CheckBox mCbCheck;

        ViewHolder(View view) {
            super(view);
            mCbCheck = (CheckBox)view.findViewById(R.id.cb_check);
        }
    }
}
